home *** CD-ROM | disk | FTP | other *** search
- { inherit.pas -- Demonstrate object inheritance }
-
- program Inherit;
-
- uses WinCrt, Strings;
-
- type
-
- PAncestor = ^TAncestor;
- TAncestor = object
- Name: PChar;
- constructor Init(P: PChar);
- destructor Done;
- procedure ChangeName(P: PChar);
- procedure ShowName;
- end;
-
- PDescendant = ^TDescendant;
- TDescendant = object(TAncestor)
- procedure ChangeName(P: PChar);
- end;
-
- { TAncestor }
-
- constructor TAncestor.Init(P: PChar);
- begin
- Name := StrNew(P)
- end;
-
- destructor TAncestor.Done;
- begin
- StrDispose(Name)
- end;
-
- procedure TAncestor.ChangeName(P: PChar);
- begin
- StrDispose(Name);
- Name := StrNew(P)
- end;
-
- procedure TAncestor.ShowName;
- begin
- WriteBuf(Name, StrLen(Name));
- WriteChar(#13);
- WriteChar(#10)
- end;
-
- { TDescendant }
-
- procedure TDescendant.ChangeName(P: PChar);
- begin
- TAncestor.ChangeName(P);
- if Name <> nil then StrUpper(Name)
- end;
-
- var
-
- Parent: PAncestor;
- Child: PDescendant;
-
- begin
- Parent := New(PAncestor, Init('String in Parent'));
- Child := New(PDescendant, Init('String in Child'));
- Parent^.ShowName;
- Child^.ShowName;
- Parent^.ChangeName('New string in Parent');
- Child^.ChangeName('New string in Child');
- Parent^.ShowName;
- Child^.ShowName;
- Dispose(Parent, Done);
- Dispose(Child, Done)
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 4/08/1991
- ---------------------------------------------------------------}
-